﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using RaytracerLib.MathLib;
using RaytracerLib.Volumes;

namespace Raytracer.PropertyGridDecorators
{
    public class ProceduralVolumeProperties
    {
        ProceduralVolume m_volume;

        public ProceduralVolumeProperties(ProceduralVolume a_layer)
        {
            m_volume = a_layer;
        }

        [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
        [Category(Categories.PROPERTIES)]
        public string[] Script
        {
            get
            {
                return m_volume.Script.Replace(
                    System.Environment.NewLine, "\n").Split(new[] { '\n' }).ToArray();
            }
            set
            {
                m_volume.Script = String.Join(System.Environment.NewLine, value);
            }
        }
    }

    public class SolidColorVolumeProperties
    {
        private SolidColorVolume m_volume;

        public SolidColorVolumeProperties(SolidColorVolume a_layer)
        {
            m_volume = a_layer;
        }

        [DisplayName("System color")]
        [Category(Categories.PROPERTIES)]
        public Color SystemColor
        {
            get
            {
                return m_volume.Color.SystemColor;
            }
            set
            {
                m_volume.Color = new ColorFloat(value);
            }
        }

        [Category(Categories.PROPERTIES)]
        [TypeConverter(typeof(ColorFloatConverter))]
        public ColorFloatProperties Color
        {
            get
            {
                return new ColorFloatProperties(
                    () => m_volume.Color,
                    (c) => m_volume.Color = c);
            }
            set
            {
                m_volume.Color = value.ToColorFloat();
            }
        }
    }

    public class SolidValueVolumeProperties
    {
        private SolidValueVolume m_volume;

        public SolidValueVolumeProperties(SolidValueVolume a_layer)
        {
            m_volume = a_layer;
        }

        [Category(Categories.PROPERTIES)]
        [TypeConverter(typeof(DoubleConverter))]
        public double Value
        {
            get
            {
                return m_volume.Value;
            }
            set
            {
                m_volume.Value = value;
            }
        }
    }

    public class TransformOperationVolumeProperties
    {
        private TransformOperationVolume m_layer;

        public TransformOperationVolumeProperties(TransformOperationVolume a_layer)
        {
            m_layer = a_layer;
        }

        [Category(Categories.PROPERTIES)]
        [TypeConverter(typeof(Matrix4Converter))]
        public Matrix4Properties Transform
        {
            get
            {
                return new Matrix4Properties(
                    () => m_layer.Transform,
                    (v) => m_layer.Transform = v); ;
            }
            set
            {
                m_layer.Transform = value.ToMatrix4();
            }
        }
    }
}